#!/bin/bash

# Create standard C source file.
# powered by bx 20150128 version 3

if [ $# -lt 1 ]; then
    echo "Usage" $0 [-f] "<file1.c> [file2.c ... filen.c]"
    exit 1
fi

IS_FORCE=0

for args in $@
do
    if [[ $args == "-f" ]]; then
        IS_FORCE=1
    elif [[ $args == *.c ]]; then
        if [ ${IS_FORCE} -eq 0 -a -e ${args} ]; then
            echo "[ERROR] The "\"${args}\"" file is exists."
        else
            touch $args
            echo -e "#include <stdio.h>\n\nint main (int argc, char *argv[])\n{\n    return 0;\n}\n" > $args
            echo "[INFO] The \""$args"\" is created."
        fi
    else
        echo "[ERROR] The \""$args"\" is not .c file."
    fi
done

